﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Collections;

namespace mealplanner.database
{
   public static class Database
    {
        public static string connection;
        public static MySqlConnection con;
        public static MySqlDataReader reader;
        public static MySqlCommand command;

        /// <summary>
        /// constructor to define server and connect with database
        /// </summary>
        public static void DatabaseConnection()
        {
            connection = "server=localhost;user id=root;persistsecurityinfo=True;password=root;database=mealplanner";
            con = new MySqlConnection(connection);
        }

        /// <summary>
        /// this method get data from database and store in reader object from mysqlDataReader.
        /// </summary>
        /// <param name="commnd"> select statement that execute</param>
        public static MySqlDataReader executeCommand(string commnd)
        {
            Database.DatabaseConnection();
            command = con.CreateCommand();
            command.CommandText = commnd;
            try
            {
                con.Open();

            }
            catch (Exception e1)
            {
                Console.WriteLine("e1.ToString" + e1.ToString());
            }
            reader = command.ExecuteReader();
            //con.Close();
            //reader.Close();
            return reader;


        }
    }

}
